package com.shrio.controller;

import com.shrio.kafka.KafkaProducerServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * Created by luojie on 2018/5/7.
 */
@Controller
public class KafkaController {

    @Autowired
    KafkaProducerServer kafkaProducerServer;

    @RequestMapping("putMessage")
    public String putMessage(String ifPartition){
        String topic = "orderTopic";
        String value = "test";
        if(ifPartition == null || ifPartition == ""){
            ifPartition = "1";
        }
        Integer partitionNum = 3;
        String role = "test";//用来生成key
        Map<String,Object> res = kafkaProducerServer.sndMesForTemplate
                (topic, value, ifPartition, partitionNum, role);

        System.out.println("测试结果如下：===============");
        String message = (String)res.get("message");
        String code = (String)res.get("code");

        System.out.println("code:"+code);
        System.out.println("message:"+message);
        return "success";
    }
}
